package org.jeecg.modules.qyxxora.service.impl;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.modules.fk.entity.DjUserInfo;
import org.jeecg.modules.qyxx.entity.BgSwzbjcOrder;
import org.jeecg.modules.qyxxora.entity.ZbjkSwzbjkjg;
import org.jeecg.modules.qyxx.entity.qo.ZbjkSwzbjkjgQo;
import org.jeecg.modules.qyxxora.mapper.ZbjkSwzbjkjgMapper;
import org.jeecg.modules.qyxx.service.IBgSwzbjcOrderService;
import org.jeecg.modules.qyxxora.service.IZbjkSwzbjkjgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 税务指标监控结果
 * @Author: ZJJ
 * @Date: 2021-06-11
 * @Version: V1.0
 */
@Service
public class ZbjkSwzbjkjgServiceImpl extends MppServiceImpl<ZbjkSwzbjkjgMapper, ZbjkSwzbjkjg> implements IZbjkSwzbjkjgService {
    @Autowired
    private ZbjkSwzbjkjgMapper zbjkSwzbjkjgMapper;
    @Autowired
    private IBgSwzbjcOrderService bgSwzbjcOrderService;

    @Override
    public ZbjkSwzbjkjg zbjkSwzbjkjg(String djxh, String ssny) {
        String[] split = ssny.substring(0, 7).split("-");
        ssny = split[0] + split[1];
        LambdaQueryWrapper<ZbjkSwzbjkjg> wrapper = Wrappers.lambdaQuery(ZbjkSwzbjkjg.class);
        wrapper.eq(ZbjkSwzbjkjg::getDjxh, djxh).eq(ZbjkSwzbjkjg::getSsny, ssny);
        return zbjkSwzbjkjgMapper.selectOne(wrapper);
    }

    @Override
    public List<BgSwzbjcOrder> selectList(ZbjkSwzbjkjgQo qo, List<DjUserInfo> djUserInfos) {
        if (djUserInfos == null || djUserInfos.size() == 0) {
            return new ArrayList<>();
        }
        List<String> nsrsbhs = new ArrayList<>();
        for (DjUserInfo djUserInfo : djUserInfos) {
            nsrsbhs.add(djUserInfo.getNsrsbh());
        }
        List<BgSwzbjcOrder> bgSwzbjcOrders = bgSwzbjcOrderService.selectList(nsrsbhs, qo.getSsny());
        for (DjUserInfo djUserInfo : djUserInfos) {
            for (BgSwzbjcOrder bgSwzbjcOrder : bgSwzbjcOrders) {
                if (djUserInfo.getNsrsbh() != null && djUserInfo.getNsrsbh().equals(bgSwzbjcOrder.getNsrsbh())) {
                    bgSwzbjcOrder.setSaleNetName(djUserInfo.getSaleNetName());
                    bgSwzbjcOrder.setSaleNetCode(djUserInfo.getSaleNetCode());
                }
            }
        }
        return bgSwzbjcOrders;
    }
}
